package com.jl.config;

import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class PageModel<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int pageNum;
    private int pageSize;
    private int size;
    private int pages;
    private long total;
    private List<T> list = new ArrayList<>();

    public PageModel(PageInfo<T> pageInfo) {
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.size = pageInfo.getSize();
        this.pages = pageInfo.getPages();
        this.total = pageInfo.getTotal();
        if (!CollectionUtils.isEmpty(pageInfo.getList())){
            this.list = pageInfo.getList();
        }
    }

    public PageModel() {

    }
}
